package com.promise.jokerdream.database.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.promise.jokerdream.database.entity.TimerTaskConfigEntity

/**
 * 定时任务配置数据访问对象
 */
@Dao
interface TimerTaskConfigDao {
    
    /**
     * 插入或更新定时任务配置
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOrUpdate(config: TimerTaskConfigEntity)
    
    /**
     * 批量插入或更新定时任务配置
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOrUpdateAll(configs: List<TimerTaskConfigEntity>)
    
    /**
     * 更新定时任务配置
     */
    @Update
    suspend fun update(config: TimerTaskConfigEntity)
    
    /**
     * 根据用户ID获取所有定时任务配置
     */
    @Query("SELECT * FROM timer_task_config WHERE userId = :userId ORDER BY id")
    suspend fun getByUserId(userId: String): List<TimerTaskConfigEntity>
    
    /**
     * 根据任务ID获取配置
     */
    @Query("SELECT * FROM timer_task_config WHERE taskId = :taskId LIMIT 1")
    suspend fun getByTaskId(taskId: String): TimerTaskConfigEntity?
    
    /**
     * 删除定时任务配置
     */
    @Delete
    suspend fun delete(config: TimerTaskConfigEntity)
    
    /**
     * 根据用户ID删除所有定时任务配置
     */
    @Query("DELETE FROM timer_task_config WHERE userId = :userId")
    suspend fun deleteByUserId(userId: String)
    
    /**
     * 根据任务ID删除配置
     */
    @Query("DELETE FROM timer_task_config WHERE taskId = :taskId")
    suspend fun deleteByTaskId(taskId: String)
}

